<template>
  <div class="app-container">
    <el-table v-loading="listLoading" element-loading-text="加载中" :data="list" border fit highlight-current-row>
      <el-table-column align="center" label="序号" width="50">
        <template slot-scope="scope">
          {{ scope.$index+1 }}
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="80" align="center">
        <template slot-scope="scope">
          {{ scope.row.realName }}
        </template>
      </el-table-column>
      <el-table-column label="手机号" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.applyPhone }}
        </template>
      </el-table-column>
      <el-table-column label="活动主题" align="center">
        <template slot-scope="scope">
          {{ scope.row.activity.activityName }}
        </template>
      </el-table-column>
      <el-table-column label="活动人数" align="center" width="80">
        <template slot-scope="scope">
          {{ scope.row.activity.maxPersonNum }}
        </template>
      </el-table-column>
      <el-table-column label="开始时间" align="center" width="170">
        <template slot-scope="scope">
          <i v-if="scope.row.activity.activityStart" class="el-icon-time" />
          <span> {{ scope.row.activity.activityStart }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" width="170">
        <template slot-scope="scope">
          <i v-if="scope.row.activity.activityEnd" class="el-icon-time" />
          <span> {{ scope.row.activity.activityEnd }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" width="170">
        <template slot-scope="scope">
          <i v-if="scope.row.applyTime" class="el-icon-time" />
          <span> {{ scope.row.applyTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核" align="center" width="150">
        <template slot-scope="scope">
          <el-button size="mini" type="success" @click="handleAudit(scope.row.id,1)">同意</el-button>
          <el-button size="mini" type="danger" @click="handleAudit(scope.row.id,2)">拒绝</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[10, 20, 40, 80]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import {
  getList,
  setInspect
} from '@/api/activity'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  components: {

  },
  data() {
    return {
      list: null,
      listLoading: true,
      detailFrom: {},
      adType: [],
      currentPage: 1,
      total: 9,
      pageSize: 10
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    // 获取表格数据
    fetchData() {
      // debugger
      // console.log('路由模式', process.env.port)
      this.listLoading = true
      const val = {
        page: this.currentPage,
        size: this.pageSize
      }
      getList(0, val).then((res) => {
        console.log(res.res.content)
        this.list = res.res.content
        this.total = res.res.totalElements
        this.currentPage = res.res.number + 1
        this.pageSize = res.res.size
        this.listLoading = false
      })
    },
    // 审核活动
    handleAudit(id, result) {
      const val = {
        applyInfoId: id,
        result: result
      }
      setInspect(val)
        .then((res) => {
          console.log(res)
          this.$message.success('操作成功')
          this.fetchData()
        })
        .catch(() => {
          this.$message.error('操作失败')
        })
    },

    // 分页
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`)
      this.currentPage = val
      this.fetchData()
    }
  }
}
</script>
